package com.cms.manage.controller;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.cms.manage.service.HelloService;
import com.cms.manage.util.ImageUtil;
import com.cms.manage.util.RequestMapToUtil;
import com.mysql.fabric.xmlrpc.base.Array;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
@Api(description = "文化云首页,活动")
//@ApiIgnore()
@RestController     //等同于同时加上了@Controller和@ResponseBody
@RequestMapping("/cms/session")
public class HelloController extends BaseController{

	
	 // @Autowired dad
	  private HelloService helloService;
	  

	  @ApiOperation(value="用户登录", notes="登录")
		@ApiImplicitParams({
		@ApiImplicitParam(name = "user_email", value = "用户名", required = true, dataType = "String",paramType = "form"),
		@ApiImplicitParam(name = "user_password", value = "用户密码", required = true, dataType = "String",paramType = "form"),
		@ApiImplicitParam(name = "ip", value = "用户IP", required = true, dataType = "String",paramType = "form"),
		@ApiImplicitParam(name = "hidden", value = "登陆类型 0:不隐身 1:隐身", required = true, dataType = "String",paramType = "form")
		})
	    @RequestMapping(value = "/Login",method = RequestMethod.POST)
	    @ResponseBody
	    public ResponseEntity<Map<String,Object>> chatlogin(HttpServletRequest request){		
			  Map<String,String> data =RequestMapToUtil.getPostByTextPlain(request);					  
	    	  Map<String, Object> result = new HashMap<String, Object>();
	    	  // result = usersService.login(data);
	    	if(result.get("code")!=null){
	    		return ResponseEntity.status(HttpStatus.OK).body(ERROR(result.get("message"),null));
	    	 }
	    	return ResponseEntity.status(HttpStatus.OK).body(SUCCESS("",result.get("message"))); 
	    }
	  
	  
	    @ApiOperation(value="用户失效校验", notes="用户失效校验")
	    @RequestMapping(value = "/check",method = RequestMethod.POST)
	    @ResponseBody
	    public ResponseEntity<Map<String,Object>> check(HttpServletRequest request){		
			  Map<String,String> data =RequestMapToUtil.getPostByTextPlain(request);					  
	    	  Map<String, Object> result = new HashMap<String, Object>();	    
	    	  return ResponseEntity.status(HttpStatus.OK).body(SUCCESS("","")); 
	    }
	  
	  
	  @ApiOperation(value="上传图片", notes="上传图片")
		@ApiImplicitParams({	
			@ApiImplicitParam(name = "user_id", value = "用户id", required = true, dataType = "String",paramType = "form"),
			@ApiImplicitParam(name = "user_name", value = "用户名", required = true, dataType = "String",paramType = "form"),
			@ApiImplicitParam(name = "type", value = "头像类型 ico:最大200*200 photo:最小200*200  ", required = true, dataType = "String",paramType = "form"),
			@ApiImplicitParam(name = "attach", value = "图片", required = true, dataType = "File",paramType = "form"),
			@ApiImplicitParam(name = "pass_key", value = "秘钥", required = true, dataType = "String",paramType = "form")				
			})
	    @RequestMapping(value = "/setUserIcon",method = RequestMethod.POST)
	    @ResponseBody
	    public ResponseEntity<Map<String,Object>> setUserIcon(HttpServletRequest request){			
			Map<String, Object> rs = null;
			 try {
			//attach 图片key	
			 rs =RequestMapToUtil.getPostByTextPlain(request,"attach");	
			} catch (Exception e) {				
				return ResponseEntity.status(HttpStatus.OK).body(SUCCESS("badFile",null)); 
			}	
			//数据集
			 Map<String,String> data =(Map<String,String>)rs.get("param");
		      //图片集
			 List<MultipartFile> fileList = (List<MultipartFile>) rs.get("fileList");
			 Map<String, String> fileRs = new HashMap<>();			 
			 Map<String, Object> result = ImageUtil.uploadImageByOneBase(fileList.get(0), fileRs);
			 if(result.get("code")!=null){
		    		return ResponseEntity.status(HttpStatus.OK).body(ERROR(result.get("message"),null));
		    	 }
		    return ResponseEntity.status(HttpStatus.OK).body(SUCCESS("",result.get("data"))); 
	  }

	  
	  
	   public static void main(String[] args) {	
		   Integer mp [] = {13,23,45,66,77,88,89,100,12,121,1211,45};
		/*   Arrays.sort(mp, new Comparator<Integer>() {
			   @Override
			   public int compare(Integer o1, Integer o2) {
			   return o2 - o1;
			   }
			   });*/
	       // Arrays.stream(mp).forEach(x->System.out.println(x));
	        Arrays.stream(mp).allMatch(x->x==13);
	        Arrays.stream(mp).forEach(x->System.out.println(x));
	/*	   for (int i = 0; i < mp.length-1; i++) {		   
			for (int j = 0; j < mp.length-1-i; j++) {
				  if(mp[j]>mp[j+1]){
					int temp =mp[j];
					mp[j]=mp[j+1];
					mp[j+1]=temp;		  
				  }				   
			}	
		}*/
		  // Arrays.stream(mp).sorted(Comparator<? super T> comparator).forEach(x->System.out.println(x));
	}
	 
}
